/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
//寻找目标值target的索引
var searchInsert = function (nums, target) {
  let left = 0, right = nums.length - 1
  while (left <= right) {
    let mid = Math.floor((left + right) / 2)
    if (nums[mid] === target) {
      return mid
    } else if (nums[mid] > target) {
      right = mid - 1
    } else {
      left = mid + 1
    }
  }

  //数组中不存在target，返回需要插入的位置（找一组数据验证即可）
  return left
};
